#ifndef MVDWINDOW_H
#define MVDWINDOW_H

#include <QMainWindow>
#include <QStringListModel>
#include <QStringList>
#include <QFileSystemModel>
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QItemDelegate>
#include <QDateTimeEdit>
#include <QSqlDatabase>
#include <QSqlError>
#include <QMessageBox>
#include <QFileDialog>
#include <QPrinter>
#include <QTextDocument>
#include "xlsxdocument.h" // 需要提前安装并包含此库

class CustomDelegate : public QItemDelegate{
    Q_OBJECT
public:
    //创建代理组件
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        Q_UNUSED(option)
        Q_UNUSED(index)
        QDateTimeEdit * tEdit = new QDateTimeEdit(parent);
        tEdit->setCalendarPopup(true);
        return tEdit;
    }
    //设置代理组件的数据
    void setEditorData(QWidget *editor, const QModelIndex &index) const
    {
        Q_UNUSED(index)
        QDateTimeEdit * tEdit = static_cast<QDateTimeEdit*>(editor);
        tEdit->setDateTime(QDateTime::currentDateTime());
    }
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
    {
        QDateTimeEdit * tEdit = static_cast<QDateTimeEdit*>(editor);
        model->setData(index,tEdit->dateTime());
    }

    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        Q_UNUSED(index)
        editor->setGeometry(option.rect);
    }
};

namespace Ui {
class MvdWindow;
}

class MvdWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MvdWindow(QWidget *parent = 0);
    ~MvdWindow();
    void initWindow(QSqlDatabase &db);

private slots:
    bool isDatabaseOpen();

    void on_addDbAction_triggered();

    void on_delDbAction_triggered();

    //void on_updateDbaction_triggered();

    //void on_sumbitAction_triggered();

    //void on_refreshAction_triggered();

    //void on_reAction_triggered();

    void on_updateDbAction_triggered();

    void on_refreshDbAction_triggered();

    void on_reDbAction_triggered();

    void on_sumbitDbAction_triggered();

    //void on_pushButton_2_clicked();

    //void on_pushButton_clicked();

    void on_pdfButton_clicked();

    void on_excelButton_clicked();

    void sortData();

private:
    Ui::MvdWindow *ui;
    QSqlTableModel *tmodel;
};

#endif // MVDWINDOW_H
